// my custom

Promise.all = function (arr) {
  return new Promise((resolve, reject) => {
    let arr_res = []
    let finishNum = 0
    for (let i = 0; i < arr.length; i++) {
      Promise.resolve(arr[i]).then(res => {
        arr_res[i] = res
        finishNum++
        if (finishNum === arr.length) {
          resolve(arr_res)
        }
      }, reason => {
        reject(reason)
      })
    }
  })
}


Promise.prototype.finally = function (callback) {
  return this.then(
    (value) => {
      return Promise.resolve(callback).then(() => value)
    },
    (err) => {
      return Promise.resolve(callback).then(() => { throw err })
    }
  )
}